//
//  WBTabBarController.swift
//  微博(swift)
//
//  Created by 汤米 on 16/4/17.
//  Copyright © 2016年 汤米. All rights reserved.
//

import UIKit

class WBTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabBar = WBTabBar()
        
        tabBar.WBdelegate = self
        
        setValue(tabBar, forKey: "tabBar")
        
        addChildViewController(WBHomeTableViewController(), imageName: "tabbar_home", title: "首页")
        addChildViewController(WBMessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController(WBDiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(WBMineTableViewController(), imageName: "tabbar_profile", title: "我的")
        

    }
    
    // MARK: -  抽离出来的添加子控制器的方法
    func addChildViewController(childController: UIViewController, imageName: String, title: String) {
        
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.title = title
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")
        
        addChildViewController(UINavigationController(rootViewController: childController))
        
    }

}


// MARK: -  相当于OC中的分类
extension WBTabBarController: WBTabBarDelegate {
    
    func writeButtonWasClick() {
        
        let composeVC = WBComposeViewController()
        presentViewController(UINavigationController(rootViewController: composeVC), animated: true, completion: nil)
    }
}